package com.qf.service.impl;

import com.qf.constant.CacheConstants;
import com.qf.constant.StrategyConstants;
import com.qf.dfa.SensitiveWordFilter;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author WzYu
 * @date 2022-6-11 上午 10:12
 */
@Service
@Slf4j
public class DirtyWordFilterServiceImpl implements FilterChainService {

    @Autowired
    private PushMsgUtil pushMsgUtil;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块 - 敏感词策略] 策略开始执行");

        SensitiveWordFilter sensitiveWordFilter = SensitiveWordFilter.getInstance();

        int c = sensitiveWordFilter.checkSensitiveWord(standardSubmit.getMessageContent(), 0, SensitiveWordFilter.minMatchType);
        if (c==0){
            log.info("[策略模块 - 敏感词策略] 敏感词策略执行成功！！！");
            return true;
        }else {
            log.info("[策略模块 - 敏感词策略] 敏感词策略执行失败！！！");
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);

            pushMsgUtil.pushReport(standardSubmit,StrategyConstants.STRATEGY_ERROR_DIRTY_WORDS);
            return false;
        }

    }
}
